﻿using System;
using System.Collections.Generic;
using Tequila.Phone.Sharing.Email;
using Tequila.Phone.Sharing.Facebook;
using Tequila.Phone.Sharing.Twitter;

namespace Tequila.Phone.Sharing
{
    /// <summary>
    /// Default <see cref="IShareServiceFactory">IShareServiceFactory</see> implementation.
    /// </summary>
    public class ShareServiceFactory : IShareServiceFactory
    {
        private readonly IDictionary<SocialNetworkType, IShareService> _senders =
            new Dictionary<SocialNetworkType, IShareService>();

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="fileStorageManager"></param>
        /// <param name="settingsService"></param>
        /// <param name="facebookAuthorizationSession"></param>
        /// <param name="twitterAuthorizationSession"></param>
        public ShareServiceFactory(
            IFileStorageManager fileStorageManager
            , ISettingsService settingsService
            , FacebookAuthorizationSession facebookAuthorizationSession
            , TwitterAuthorizationSession twitterAuthorizationSession)
        {
            _senders[SocialNetworkType.Email] = new EmailShareService(
                fileStorageManager);
            _senders[SocialNetworkType.Facebook] = new FacebookShareService(
                settingsService, fileStorageManager,
                facebookAuthorizationSession);
            _senders[SocialNetworkType.Twitter] = new TwitterShareService(
                settingsService, twitterAuthorizationSession);
        }

        /// <summary>
        /// Returns <see cref="IShareService">IShareService</see> implementation by Social Network <see cref="SocialNetworkType">type</see>.
        /// </summary>
        /// <param name="type">Social Network <see cref="SocialNetworkType">Type</see>.</param>
        /// <returns><see cref="IShareService">IShareService</see> implementation.</returns>
        /// <exception cref="NotSupportedException">Raised when <paramref name="type"/> is not supported.</exception>
        public IShareService GetShareService(SocialNetworkType type)
        {
            if (_senders.ContainsKey(type))
            {
                return _senders[type];
            }

            throw new NotSupportedException();
        }
    }
}
